﻿using System.Collections.Generic;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;

namespace OurWedding1.IO
{
    public class TableRenderer:IRendererable
    {
        public List<IPdfPTableCreatable> Rows { get; set; }

        public TableRenderer()
        {
            Rows = new List<IPdfPTableCreatable>();
        }

        public void Render(Stream output)
        {
            var document = new Document(PageSize.A4, 25, 25, 30, 30);
            try
            {
                var writer = PdfWriter.GetInstance(document, output);
                document.Open();
                var table = new PdfPTable(1);
                foreach (var item in Rows)
                {
                    var cell = new PdfPCell(item.CreateTable());
                    table.AddCell(cell);
                }
                document.Add(table);
                writer.Flush();
            }
            finally
            {

                document.Close();
            }
        }
    }
}